package geektime.concurrent.part2.concurrencycontrol;

import java.time.Instant;
import java.util.concurrent.Phaser;

public class PhaserWorker extends Thread {
    private String name;

    private Phaser phaser;

    public PhaserWorker(String name, Phaser phaser) {
        setName(name);
        this.phaser = phaser;
        phaser.register(); // 在构造方法中完成注册的动作
    }

    @Override
    public void run() {
        System.out.printf("[%s]已创建，阻塞在arriveAndAwaitAdvance\n", getName());
        phaser.arriveAndAwaitAdvance();
        System.out.printf("[%s]开始执行了，time=%s\n", getName(), Instant.now());
    }
}
